< previous page page_471 next page >

Page 471
FormatPercent()
The FormatPercent() function returns a fractional value in a percentage format. This is ideal for those situations where you need to display a percentage valuesuch as on top of a progress bar, for example:
9f31265bb40b592b1929e18a47ab28e5.gif
FormatPercent(10/60) = 16.6667%
FormatPercent(1/3,-1,vbFalse) = 33.33%
FormatPercent(1/3,-1,vbFalse) = 33.33%
FormatPercent(-1 / -2,-1, , vbFalse) = 50.00%
FormatPercent(-1 / -2,-1, , vbUseDefault) = 50.00%
FormatPercent(.11,-1, , ,vbFalse) = 11.00%
FormatPercent(.11,-1, , , vbUseDefault) = 11.00%
Round()
The Round() function is very unique, shall we say? It doesnt work exactly like you might think it would. For example, I was always taught that if a value is .4 or below, you round down to the next lowest whole number, whereas if a value is .5 or above, you round to next higher whole number. Lets take a look at some sample output to see how Visual Basic performs rounding.
9f31265bb40b592b1929e18a47ab28e5.gif
Round(1.4) = 1
Round(1.5) = 2
Round(1.6) = 2

Round(2.4) = 2
Round(2.5) = 2
Round(2.6) = 3
As you can see, when you pass 1.5 to the Round() function, it rounds up. When you pass 2.5 to the Round() function, it rounds down. Visual Basic always rounds up numbers that are even and rounds down numbers that are odd. Although most people call this a bug, the folks at Microsoft call it a feature, claiming that if you perform a lot of rounding, statistically this will give you more accurate results. Yeah, right! Of course, you can always go back to your seventh grade math book and write your own function to get a real rounding function.

 
< previous page page_471 next page >

If you like this book, buy it!